<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="java.util.*,linuxbox.calendar.logic.*,linuxbox.calendar.bean.*" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="common" %>
<%@ taglib uri="/linuxbox/Calendar.tld" prefix="Calendar" %>

<%
  String DEFAULT_VIEW = (String)request.getAttribute("DEFAULT_VIEW");
  int TIME_INTERVAL = Integer.parseInt((String)request.getAttribute("TIME_INTERVAL"));
  int WEEK_START_DAY = Integer.parseInt((String)request.getAttribute("WEEK_START_DAY"));
  int WORK_START_HOUR = Integer.parseInt((String)request.getAttribute("WORK_START_HOUR"));
  int WORK_END_HOUR = Integer.parseInt((String)request.getAttribute("WORK_END_HOUR"));
  int ENTRIES_PER_PAGE = Integer.parseInt((String)request.getAttribute("ENTRIES_PER_PAGE"));
  int DST = Integer.parseInt((String)request.getAttribute("DST"));
  String TIMEZONE = (String)request.getAttribute("TIMEZONE");
%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<script LANGUAGE="JavaScript">
function onAdd()
{
  var choice = document.theForm.CHOICE.value;
  if ( choice != null && choice.length > 0 )
  {
    var option = new Option(choice, choice);
    document.theForm.CATEGORIES.options[document.theForm.CATEGORIES.length] = option;
    document.theForm.CHOICE.value = "";
    document.theForm.CHOICE.focus();
  }
}

function onRemove()
{
  var options = document.theForm.CATEGORIES.options;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      if (options[i].selected == true)
        options[i] = null;
    }
  }
//	document.theForm.CATEGORIES.focus();
}

//select all the items so they will be sent out
function onSubmit()
{
//	alert("Set selected");
  if (isNaN(parseInt(document.theForm.ENTRIES_PER_PAGE.value)))
  {
    alert("The value you entered is not a number");
    document.theForm.ENTRIES_PER_PAGE.select();
    document.theForm.ENTRIES_PER_PAGE.focus();
    return false;
  }

  var options = document.theForm.CATEGORIES.options;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      options[i].selected = true;
    }
//		alert("Set selected");
  }
}

function onExport()
{
  var fromYear = parseInt(document.theForm.FROM_YEAR.options[document.theForm.FROM_YEAR.selectedIndex].value);
  var toYear = parseInt(document.theForm.TO_YEAR.options[document.theForm.TO_YEAR.selectedIndex].value);

  if ( (toYear > fromYear)
  || ( (toYear == fromYear)
      && (document.theForm.TO_MONTH.selectedIndex > document.theForm.FROM_MONTH.selectedIndex) )
  || ( (toYear == fromYear)
      && (document.theForm.TO_MONTH.selectedIndex == document.theForm.FROM_MONTH.selectedIndex)
      && (document.theForm.TO_DAY.selectedIndex > document.theForm.FROM_DAY.selectedIndex) ) )
      return true;
  alert("Invalid date range!");
  return false;
}
</script>

<FORM action="<%=BoxStatic.servletDir%>BoxCalendarSettingsAction" method=post name=theForm>

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
<tr><td>
    &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
    <b><%=boxName%> - Calendar Settings</b>
</td></tr>
</table>

<hr width="100%" color=#E06000 align=left>

<!-- TODO: Add error checking for work start hour - work end hour -->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD></TD>
    <TD></TD>
    <TD vAlign=top width="100%">
        <TABLE cellSpacing=0 cellPadding=4 width="100%" border=0>
          <TBODY>
          <TR >
            <TD noWrap>
              <INPUT type=submit value=&nbsp;&nbsp;Save&nbsp;&nbsp; name=SubmitSave onclick="return onSubmit()">
              &nbsp;
              <INPUT type=submit value=&nbsp;Cancel&nbsp; name=SubmitCancel>
              &nbsp;
              &nbsp;
              &nbsp;
              <INPUT type=submit value="Clear Calendar" name=SubmitClear>
            </TD>
          </TR>
          </TBODY>
        </TABLE>
        <TABLE cellSpacing=0 cellPadding=4 width="100%" border=1>
          <TBODY>
          <TR bgcolor="#7EC1F3">
            <TD colSpan=2> <B><font size="+1">Calendar Views</font></B></TD>
          </TR>
          <TR >
            <TD noWrap width="1%">Default View:</TD>
            <TD>
              <SELECT style="WIDTH: 12em" name=DEFAULT_VIEW>
                <OPTION value="day" <% if (DEFAULT_VIEW.compareTo("day") == 0) out.print("selected"); %>>Day</OPTION>
                <OPTION value="week" <% if (DEFAULT_VIEW.compareTo("week") == 0) out.print("selected"); %>>Week</OPTION>
                <OPTION value="month" <% if (DEFAULT_VIEW.compareTo("month") == 0) out.print("selected"); %>>Month</OPTION>
                <OPTION value="year" <% if (DEFAULT_VIEW.compareTo("year") == 0) out.print("selected"); %>>Year</OPTION>
              </SELECT>
            </TD>
          </TR>
          <TR >
            <TD noWrap width="1%">Time Intervals:</TD>
            <TD>
              <SELECT style="WIDTH: 12em" name=TIME_INTERVAL>
                <OPTION value=5 <% if (TIME_INTERVAL==5) out.print("selected"); %> >5 minutes</OPTION>
                <OPTION value=10 <% if (TIME_INTERVAL==10) out.print("selected"); %>>10 minutes</OPTION>
                <OPTION value=15 <% if (TIME_INTERVAL==15) out.print("selected"); %>>15 minutes</OPTION>
                <OPTION value=20 <% if (TIME_INTERVAL==20) out.print("selected"); %> >20 minutes</OPTION>
                <OPTION value=30 <% if (TIME_INTERVAL==30) out.print("selected"); %>>30 minutes</OPTION>
                <OPTION value=60 <% if (TIME_INTERVAL==60) out.print("selected"); %>>1 hour</OPTION>
              </SELECT>
            </TD>
          </TR>
          <TR >
            <TD noWrap width="1%">Week Start Day:</TD>
            <TD>
              <SELECT style="WIDTH: 12em" name=WEEK_START_DAY>
              <!-- use the value as the one in Calendar -->
                <OPTION value=0 <% if (WEEK_START_DAY==0) out.print("selected"); %>>Current Day</OPTION>
                <OPTION value=2 <% if (WEEK_START_DAY==2) out.print("selected"); %>>Monday</OPTION>
                <OPTION value=3 <% if (WEEK_START_DAY==3) out.print("selected"); %>>Tuesday</OPTION>
                <OPTION value=4 <% if (WEEK_START_DAY==4) out.print("selected"); %>>Wednesday</OPTION>
                <OPTION value=5 <% if (WEEK_START_DAY==5) out.print("selected"); %>>Thursday</OPTION>
                <OPTION value=6 <% if (WEEK_START_DAY==6) out.print("selected"); %>>Friday</OPTION>
                <OPTION value=7 <% if (WEEK_START_DAY==7) out.print("selected"); %>>Saturday</OPTION>
                <OPTION value=1 <% if (WEEK_START_DAY==1) out.print("selected"); %>>Sunday</OPTION>
              </SELECT>
            </TD>
          </TR>
          <TR>
            <TD vAlign=top noWrap width="1%">Working Hours:</TD>
            <TD>
              <TABLE cellSpacing=0 cellPadding=2 border=0>
                <TBODY>
                <TR>
                  <TD noWrap align=left width="1%">Start day at</TD>
                  <TD noWrap width="1%">
                    <select  name="WORK_START_HOUR" size="1">
                      <common:HourList selected="<%=WORK_START_HOUR%>" allownull="false" />
                    </select>
                  </TD>
                  <TD noWrap align=left width="1%">End day at</TD>
                  <TD>
                    <select  name="WORK_END_HOUR" size="1">
                      <common:HourList selected="<%=WORK_END_HOUR%>" allownull="false" />
                    </select>
                  </TD>
                </TR>
                </TBODY>
              </TABLE>
            </TD>
          </TR>
          <TR bgcolor="#7EC1F3">
            <TD colSpan=2> <B><font size="+1">Date &amp; Time</font></B></TD>
          </TR>
          <TR >
            <TD noWrap width="1%">Time Zone:</TD>
            <TD>
              <SELECT size=1 name="TIMEZONE">
            	  <Calendar:CalendarTimeZone defaultTZ="<%=TIMEZONE%>"/>
              </SELECT>
            </TD>
          </TR>
          <TR>
            <TD noWrap width="1%">Daylight Savings Time:</TD>
            <TD>
              <SELECT name=DST>
                <OPTION value=<% out.print(sec.DST_ON); if (DST==sec.DST_ON) out.print(" selected");%>>On</OPTION>
                <OPTION value=<% out.print(sec.DST_OFF); if (DST==sec.DST_OFF) out.print(" selected");%>>Off</OPTION>
                <OPTION value=<% out.print(sec.DST_AUTO); if (DST==sec.DST_AUTO) out.print(" selected");%>>Automatic (U.S. only)</OPTION>
              </SELECT>
            </TD>
          </TR>
      		<TR bgcolor="#7EC1F3">
            <TD colSpan=2> <B><font size="+1">Event List</font></B>
            </TD>
      		</TR>
      <TR>
      	<TD colspan=2>Display
          <select name="ENTRIES_PER_PAGE" size="1" >
            <OPTION value=5 <% if (ENTRIES_PER_PAGE==5) out.print("selected");%>>5</OPTION>
            <OPTION value=10 <% if (ENTRIES_PER_PAGE==10) out.print("selected");%>>10</OPTION>
            <OPTION value=20 <% if (ENTRIES_PER_PAGE==20) out.print("selected");%>>20</OPTION>
            <OPTION value=30 <% if (ENTRIES_PER_PAGE==30) out.print("selected");%>>30</OPTION>
            <OPTION value=50 <% if (ENTRIES_PER_PAGE==50) out.print("selected");%>>50</OPTION>
            <OPTION value=100 <% if (ENTRIES_PER_PAGE==100) out.print("selected");%>>100</OPTION>
            <OPTION value=200 <% if (ENTRIES_PER_PAGE==200) out.print("selected");%>>200</OPTION>
          </select>
          entries per page when listing the events.
        </TD>
    	</TR>
      <TR bgcolor="#7EC1F3">
        <TD colSpan=2> <B><font size="+1">Event Type Categories</font></B>
        </TD>
      </TR>
      <TR>
				<TD colSpan=2>
        	<table width= "100%" border=0 cellspacing=0 cellpadding=0>
          	<tr><td>
              <input type=text name="CHOICE" size=40 maxlength=200>
              <input type="button" value="Add Category" name="Add" onclick="onAdd()">
	          </td></tr>
  	        <tr><td>
	  	        Current categories:   <input type="button" value="Remove Selected" name="Remove" onclick="onRemove()">
      	    </td></tr>
        	  <tr><td>
          	  <select name="CATEGORIES" size="5" multiple>
            	  <Calendar:CalendarCatList selected="" showsystemcat="false" showallcategories="false" userid="<%=curID%>"/>
	            </select>
  	        </td></tr>
    	   	</table>
      </TD>
    </TR>
    <TR bgcolor="#7EC1F3">
      <TD colSpan=2> <B><font size="+1">Import/Export</font></B>
      </TD>
    </TR>
    <TR>
      <TD colSpan=2>
        Select export format:<br/>
        <select name="EXPORT_FORMAT" size="1" >
          <OPTION value=1>Comma Separated Value (.csv) file</OPTION>
          <OPTION value=2>iCalendar or vCalendar (.vcs) file</OPTION>
          <OPTION value=3>Date Book Archive (.dba) file</OPTION>
        </select>
      </td>
    </TR>
    <TR>
      <TD colSpan=2>
        Select exporting date range:<br/>
          From
            <select name="FROM_MONTH" size="1">
              <common:MonthList selected="1" allownull="false" />
            </select>
            <select name="FROM_DAY" size="1">
              <common:DayList selected="1" allownull="false" />
            </select>
            <select name="FROM_YEAR" size="1">
              <common:YearList selected="2003" allownull="false" />
            </select>
          &nbsp;To&nbsp;
          <select name="TO_MONTH" size="1">
            <common:MonthList selected="1" allownull="false" />
          </select>
          <select name="TO_DAY" size="1">
            <common:DayList selected="1" allownull="false" />
          </select>
          <select name="TO_YEAR" size="1">
            <common:YearList selected="2004" allownull="false" />
          </select>
          &nbsp;<INPUT type=submit value="Export" name=SubmitExport  onclick="return onExport()">
      </TD>
  	</TR>

    </TBODY>
    </TABLE>
    <TABLE cellSpacing=0 cellPadding=4 width="100%" border=0>
    <TBODY>
    	<TR>
        <TD noWrap>
          <INPUT type=submit value=&nbsp;&nbsp;Save&nbsp;&nbsp; name=SubmitSave onclick="return onSubmit()">
            &nbsp;
            <INPUT type=submit value=&nbsp;Cancel&nbsp; name=SubmitCancel>
         </TD>
     	</TR>
      </TBODY>
      </TABLE>
    </TD>
  </TR>
  </TBODY>
</TABLE>

<hr width="100%" color=#E06000 align=left>

</FORM>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
